package com.nenglai.common.resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共资源容器
 *
 * @author kongdehui
 * @date 2021/04/21 16:46
 **/
@Component
public class ResourceContainer {

    private final Map<String, ResourceService<?>> resourceServiceHashMap = new HashMap<>();

    /**
     * 将ResourceService
     * @author kongdehui
     * @date 2021/04/21 16:52
     * @param services
     * @return void
     */
    @Autowired(required = false)
    private synchronized void init(ResourceService<?>[] services) {
        for (ResourceService<?> service : services) {
            resourceServiceHashMap.put(service.resourceName(), service);
        }
    }

    /**
     * 获取ResourceService
     * @author kongdehui
     * @date 2021/04/21 16:51
     * @param apiName
     * @return com.xiaositea.admin.modular.system.service.ResourceService<?>
     */
    public ResourceService<?> getResourceService(String apiName) {
        return resourceServiceHashMap.get(apiName);
    }
}
